﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using OracleDataToRedis.Utils;
using OracleDataToRedis.Domain;

namespace OracleDataToRedis.Coders.Persistence
{
    public class EntityDaoCoder
    {
        public static void Write()
        {
            string path = BaseParams.PersistencePath;
            if (Directory.Exists(path) == false)
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, "EntityDao.cs");

            #region 创建cs文件
            FileStream file = new FileStream(path, FileMode.Create);
            StreamWriter sw = new StreamWriter(file, Encoding.UTF8);
            CommentsCoder.CreateCsComments("NH持久层操作类", sw);

            sw.WriteLine("using System;");
            sw.WriteLine("using System.Data;");
            sw.WriteLine("using System.Collections.Generic;");
            sw.WriteLine("using System.Collections;");
            sw.WriteLine("");
            sw.WriteLine("using NHibernate;");
            sw.WriteLine("using " + BaseParams.DomainNameSpace + ";");
            sw.WriteLine("");
            sw.WriteLine("namespace " + BaseParams.PersistenceNameSpace + "");
            sw.WriteLine("{");
            sw.WriteLine("    public partial class EntityDao<T> where T : BaseEntity");
            sw.WriteLine("    {");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 保存对象或更新对象");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"entity\">需要保存的对象</param>");
            sw.WriteLine("        public void SaveOrUpdate(T entity)");
            sw.WriteLine("        {");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            using (ITransaction trans = session.BeginTransaction())");
            sw.WriteLine("            {");
            sw.WriteLine("                try");
            sw.WriteLine("                {");
            sw.WriteLine("                    if (entity.DataCreateTime == null)");
            sw.WriteLine("                        entity.DataCreateTime = System.DateTime.Now;");
            sw.WriteLine("                    entity.DataUpdateTime = System.DateTime.Now;");
            sw.WriteLine("");
            sw.WriteLine("                    session.SaveOrUpdate(entity);");
            sw.WriteLine("                    trans.Commit();");
            sw.WriteLine("                }");
            sw.WriteLine("                catch (Exception)");
            sw.WriteLine("                {");
            sw.WriteLine("                    trans.Rollback();");
            sw.WriteLine("                    throw;");
            sw.WriteLine("                }");
            sw.WriteLine("                finally");
            sw.WriteLine("                {");
            sw.WriteLine("                    session.Disconnect();");
            sw.WriteLine("                }");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 保存对象或更新对象集合");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"entitys\">需要保存的对象结婚</param>");
            sw.WriteLine("        public void SaveOrUpdate(IList<T> entitys)");
            sw.WriteLine("        {");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            using (ITransaction trans = session.BeginTransaction())");
            sw.WriteLine("            {");
            sw.WriteLine("                try");
            sw.WriteLine("                {");
            sw.WriteLine("                    DateTime dtNow = DateTime.Now;");
            sw.WriteLine("                    foreach (T entity in entitys)");
            sw.WriteLine("                    {");
            sw.WriteLine("                        if (entity.DataCreateTime == null)");
            sw.WriteLine("                            entity.DataCreateTime = dtNow;");
            sw.WriteLine("                        entity.DataUpdateTime = dtNow;");
            sw.WriteLine("");
            sw.WriteLine("                        session.SaveOrUpdate(entity);");
            sw.WriteLine("                    }");
            sw.WriteLine("                    trans.Commit();");
            sw.WriteLine("                }");
            sw.WriteLine("                catch (Exception)");
            sw.WriteLine("                {");
            sw.WriteLine("                    trans.Rollback();");
            sw.WriteLine("                    throw;");
            sw.WriteLine("                }");
            sw.WriteLine("                finally");
            sw.WriteLine("                {");
            sw.WriteLine("                    session.Disconnect();");
            sw.WriteLine("                }");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 保存对象对象");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"entity\">需要保存的对象</param>");
            sw.WriteLine("        public object Save(T entity)");
            sw.WriteLine("        {");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            using (ITransaction trans = session.BeginTransaction())");
            sw.WriteLine("            {");
            sw.WriteLine("                try");
            sw.WriteLine("                {");
            sw.WriteLine("                    if (entity.DataCreateTime == null)");
            sw.WriteLine("                        entity.DataCreateTime = System.DateTime.Now;");
            sw.WriteLine("                    entity.DataUpdateTime = System.DateTime.Now;");
            sw.WriteLine("");
            sw.WriteLine("                    object id = session.Save(entity);");
            sw.WriteLine("                    trans.Commit();");
            sw.WriteLine("                    return id;");
            sw.WriteLine("                }");
            sw.WriteLine("                catch (Exception)");
            sw.WriteLine("                {");
            sw.WriteLine("                    trans.Rollback();");
            sw.WriteLine("                    throw;");
            sw.WriteLine("                }");
            sw.WriteLine("                finally");
            sw.WriteLine("                {");
            sw.WriteLine("                    session.Disconnect();");
            sw.WriteLine("                }");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 更新对象");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"entity\">需要更新的对象</param>");
            sw.WriteLine("        /// <param name=\"key\">更新对象的原始主键</param>");
            sw.WriteLine("        public void Update(T entity, object key)");
            sw.WriteLine("        {");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            using (ITransaction trans = session.BeginTransaction())");
            sw.WriteLine("            {");
            sw.WriteLine("                try");
            sw.WriteLine("                {");
            sw.WriteLine("                    if (entity.DataCreateTime == null)");
            sw.WriteLine("                        entity.DataCreateTime = System.DateTime.Now;");
            sw.WriteLine("                    entity.DataUpdateTime = System.DateTime.Now;");
            sw.WriteLine("");
            sw.WriteLine("                    if (!entity.EntityID.Equals(key))");
            sw.WriteLine("                    {                        ");
            sw.WriteLine("                        session.Delete(session.Get(typeof(T), key));");
            sw.WriteLine("                        session.Save(entity);");
            sw.WriteLine("                    }");
            sw.WriteLine("                    else");
            sw.WriteLine("                    {");
            sw.WriteLine("                        session.Update(entity, key);");
            sw.WriteLine("                    }");
            sw.WriteLine("                    trans.Commit();");
            sw.WriteLine("                }");
            sw.WriteLine("                catch (Exception)");
            sw.WriteLine("                {");
            sw.WriteLine("                    trans.Rollback();");
            sw.WriteLine("                    throw;");
            sw.WriteLine("                }");
            sw.WriteLine("                finally");
            sw.WriteLine("                {");
            sw.WriteLine("                    session.Disconnect();");
            sw.WriteLine("                }");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 删除对象");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"entity\">需要删除的对象</param>");
            sw.WriteLine("        public void Delete(T entity)");
            sw.WriteLine("        {");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            using (ITransaction trans = session.BeginTransaction())");
            sw.WriteLine("            {");
            sw.WriteLine("                try");
            sw.WriteLine("                {");
            sw.WriteLine("                    session.Delete(entity);");
            sw.WriteLine("                    trans.Commit();");
            sw.WriteLine("                }");
            sw.WriteLine("                catch (Exception)");
            sw.WriteLine("                {");
            sw.WriteLine("                    trans.Rollback();");
            sw.WriteLine("                    throw;");
            sw.WriteLine("                }");
            sw.WriteLine("                finally");
            sw.WriteLine("                {");
            sw.WriteLine("                    session.Disconnect();");
            sw.WriteLine("                }");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 删除对象数组");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"entitys\">需要删除的对象数组</param>");
            sw.WriteLine("        public void Delete(IList<T> entitys)");
            sw.WriteLine("        {");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            using (ITransaction trans = session.BeginTransaction())");
            sw.WriteLine("            {");
            sw.WriteLine("                try");
            sw.WriteLine("                {");
            sw.WriteLine("                    foreach (T entity in entitys)");
            sw.WriteLine("                    {");
            sw.WriteLine("                        session.Delete(entity);");
            sw.WriteLine("                    }");
            sw.WriteLine("                    trans.Commit();");
            sw.WriteLine("                }");
            sw.WriteLine("                catch (Exception)");
            sw.WriteLine("                {");
            sw.WriteLine("                    trans.Rollback();");
            sw.WriteLine("                    throw;");
            sw.WriteLine("                }");
            sw.WriteLine("                finally");
            sw.WriteLine("                {");
            sw.WriteLine("                    session.Disconnect();");
            sw.WriteLine("                }");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 通过主键返回对应的对象");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"id\">对象主键</param>");
            sw.WriteLine("        /// <returns>对象</returns>");
            sw.WriteLine("        public T Get(object id)");
            sw.WriteLine("        {");
            sw.WriteLine("            T t = default(T);");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                t = session.Get<T>(id);");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception)");
            sw.WriteLine("            {");
            sw.WriteLine("                throw;");
            sw.WriteLine("            }");
            sw.WriteLine("            finally");
            sw.WriteLine("            {");
            sw.WriteLine("                session.Disconnect();");
            sw.WriteLine("            }");
            sw.WriteLine("            return t;");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public T UniqueResult(String hql, params object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            return (T)this.UniqueObjectResult(hql, ps);");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public Object UniqueObjectResult(String hql, params object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            Object obj = null;");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                IQuery q = session.CreateQuery(hql);");
            sw.WriteLine("                if (ps != null)");
            sw.WriteLine("                    for (int i = 0; i < ps.Length; i++)");
            sw.WriteLine("                    {");
            sw.WriteLine("                        q.SetParameter(i, ps[i]);");
            sw.WriteLine("                    }");
            sw.WriteLine("                obj = q.UniqueResult();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception)");
            sw.WriteLine("            {");
            sw.WriteLine("                throw;");
            sw.WriteLine("            }");
            sw.WriteLine("            finally");
            sw.WriteLine("            {");
            sw.WriteLine("                session.Disconnect();");
            sw.WriteLine("            }");
            sw.WriteLine("            return obj;");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public IList<T> Query(String hql)");
            sw.WriteLine("        {");
            sw.WriteLine("            return this.Query(hql, 0, 0);");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public IList<T> Query(String hql, params object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            return this.Query(hql, 0, 0, ps);");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public IList<T> Query(String hql, long fristResult, long maxResults)");
            sw.WriteLine("        {");
            sw.WriteLine("            return this.Query(hql, fristResult, maxResults, new Object[0]);");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public IList<T> Query(String hql, long fristResult, long maxResults,");
            sw.WriteLine("                params object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            IList<T> list = null;");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                IQuery q = session.CreateQuery(hql);");
            sw.WriteLine("                if (ps != null)");
            sw.WriteLine("                    for (int i = 0; i < ps.Length; i++)");
            sw.WriteLine("                    {");
            sw.WriteLine("                        q.SetParameter(i, ps[i]);");
            sw.WriteLine("                    }");
            sw.WriteLine("                if (maxResults > 0)");
            sw.WriteLine("                {");
            sw.WriteLine("                    q.SetFirstResult((int)fristResult);");
            sw.WriteLine("                    q.SetMaxResults((int)maxResults);");
            sw.WriteLine("                }");
            sw.WriteLine("                list = q.List<T>();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception)");
            sw.WriteLine("            {");
            sw.WriteLine("                throw;");
            sw.WriteLine("            }");
            sw.WriteLine("            finally");
            sw.WriteLine("            {");
            sw.WriteLine("                session.Disconnect();");
            sw.WriteLine("            }");
            sw.WriteLine("            return list;");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public IList SqlQuery(String sql)");
            sw.WriteLine("        {");
            sw.WriteLine("            return this.SqlQuery(sql, 0, 0);");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public IList SqlQuery(String sql, params object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            return this.SqlQuery(sql, 0, 0, ps);");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        public IList SqlQuery(String sql, long fristResult, long maxResults)");
            sw.WriteLine("        {");
            sw.WriteLine("            return this.SqlQuery(sql, fristResult, maxResults, new Object[0]);");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 通过sql语句进行查询");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"sql\"></param>");
            sw.WriteLine("        /// <param name=\"fristResult\"></param>");
            sw.WriteLine("        /// <param name=\"maxResults\"></param>");
            sw.WriteLine("        /// <param name=\"ps\"></param>");
            sw.WriteLine("        /// <returns></returns>");
            sw.WriteLine("        public IList<U> SqlQuery<U>(String sql, long fristResult, long maxResults,");
            sw.WriteLine("                params object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            IList<U> list = null;");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                IQuery q = session.CreateSQLQuery(sql);");
            sw.WriteLine("                if (ps != null)");
            sw.WriteLine("                    for (int i = 0; i < ps.Length; i++)");
            sw.WriteLine("                    {");
            sw.WriteLine("                        q.SetParameter(i, ps[i]);");
            sw.WriteLine("                    }");
            sw.WriteLine("                if (maxResults > 0)");
            sw.WriteLine("                {");
            sw.WriteLine("                    q.SetFirstResult((int)fristResult);");
            sw.WriteLine("                    q.SetMaxResults((int)maxResults);");
            sw.WriteLine("                }");
            sw.WriteLine("                list = q.List<U>();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception)");
            sw.WriteLine("            {");
            sw.WriteLine("                throw;");
            sw.WriteLine("            }");
            sw.WriteLine("            finally");
            sw.WriteLine("            {");
            sw.WriteLine("                session.Disconnect();");
            sw.WriteLine("            }");
            sw.WriteLine("            return list;");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 通过hql语句进行查询");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"hql\"></param>");
            sw.WriteLine("        /// <param name=\"fristResult\"></param>");
            sw.WriteLine("        /// <param name=\"maxResults\"></param>");
            sw.WriteLine("        /// <param name=\"ps\"></param>");
            sw.WriteLine("        /// <returns>对象List集合</returns>");
            sw.WriteLine("        public IList hqlQuery(String hql, long fristResult, long maxResults,");
            sw.WriteLine("                params object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            IList list = null;");
            sw.WriteLine("            ISession session = SessionFactory.GetCurrentSession();");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                IQuery q = session.CreateQuery(hql);");
            sw.WriteLine("                if (ps != null)");
            sw.WriteLine("                    for (int i = 0; i < ps.Length; i++)");
            sw.WriteLine("                    {");
            sw.WriteLine("                        q.SetParameter(i, ps[i]);");
            sw.WriteLine("                    }");
            sw.WriteLine("                if (maxResults > 0)");
            sw.WriteLine("                {");
            sw.WriteLine("                    q.SetFirstResult((int)fristResult);");
            sw.WriteLine("                    q.SetMaxResults((int)maxResults);");
            sw.WriteLine("                }");
            sw.WriteLine("                list = q.List();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception)");
            sw.WriteLine("            {");
            sw.WriteLine("                throw;");
            sw.WriteLine("            }");
            sw.WriteLine("            finally");
            sw.WriteLine("            {");
            sw.WriteLine("                session.Disconnect();");
            sw.WriteLine("            }");
            sw.WriteLine("            return list;");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 直接调用存储过程");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"procString\"></param>");
            sw.WriteLine("        /// <param name=\"ps\"></param>");
            sw.WriteLine("        public void callProcedure(String procString, params object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            IDbCommand cmd = null;");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                cmd = SessionFactory.GetCurrentSession().Connection.CreateCommand();");
            sw.WriteLine("                cmd.CommandType = CommandType.StoredProcedure;");
            sw.WriteLine("                if (ps != null)");
            sw.WriteLine("                {");
            sw.WriteLine("                    foreach (Object obj in ps)");
            sw.WriteLine("                    {");
            sw.WriteLine("                        cmd.Parameters.Add(obj);");
            sw.WriteLine("                    }");
            sw.WriteLine("                }");
            sw.WriteLine("                cmd.ExecuteNonQuery();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                throw new Exception(\"调用存储过程的时候发生错误[sql = \" + procString + \"]\", ex);");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 执行无返回值的SQL语句");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"sql\">SQL语句</param>");
            sw.WriteLine("        /// <param name=\"session\">连接状态</param>");
            sw.WriteLine("        /// <param name=\"ps\">参数</param>");
            sw.WriteLine("        /// <returns>影响的行数</returns>");
            sw.WriteLine("        public int SqlExecuteNonQuery(String sql, params Object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            IDbConnection connection = SessionFactory.GetCurrentSession().Connection;");
            sw.WriteLine("            IDbCommand cmd = connection.CreateCommand();");
            sw.WriteLine("            cmd.CommandText = sql;");
            sw.WriteLine("            if (ps != null)");
            sw.WriteLine("                for (int i = 0; i < ps.Length; i++)");
            sw.WriteLine("                {");
            sw.WriteLine("                    cmd.Parameters.Add(ps[i]);");
            sw.WriteLine("                }");
            sw.WriteLine("            return cmd.ExecuteNonQuery();");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 通过执行Sql语句，返回DataTable");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"sql\"></param>");
            sw.WriteLine("        /// <param name=\"ps\"></param>");
            sw.WriteLine("        /// <returns></returns>");
            sw.WriteLine("        public DataTable SqlFillDataTable(String sql, params Object[] ps)");
            sw.WriteLine("        {");
            sw.WriteLine("            IDbConnection connection = SessionFactory.GetCurrentSession().Connection;");
            sw.WriteLine("            IDbCommand command = connection.CreateCommand();");
            sw.WriteLine("            command.CommandText = sql;");
            sw.WriteLine("            command.ExecuteNonQuery();");
            sw.WriteLine("            if (ps != null)");
            sw.WriteLine("                for (int i = 0; i < ps.Length; i++)");
            sw.WriteLine("                {");
            sw.WriteLine("                    command.Parameters.Add(ps[i]);");
            sw.WriteLine("                }");
            sw.WriteLine("            IDataReader reader = command.ExecuteReader();");
            sw.WriteLine("            DataTable result = new DataTable();");
            sw.WriteLine("            //result.Load(reader);//此方法亦可");
            sw.WriteLine("            DataTable schemaTable = reader.GetSchemaTable();");
            sw.WriteLine("            for (int i = 0; i < schemaTable.Rows.Count; i++)");
            sw.WriteLine("            {");
            sw.WriteLine("                string columnName = schemaTable.Rows[i][0].ToString();");
            sw.WriteLine("                result.Columns.Add(columnName);");
            sw.WriteLine("            }");
            sw.WriteLine("            while (reader.Read())");
            sw.WriteLine("            {");
            sw.WriteLine("                int fieldCount = reader.FieldCount;");
            sw.WriteLine("                object[] values = new Object[fieldCount];");
            sw.WriteLine("                for (int i = 0; i < fieldCount; i++)");
            sw.WriteLine("                {");
            sw.WriteLine("                    values[i] = reader.GetValue(i);");
            sw.WriteLine("                }");
            sw.WriteLine("                result.Rows.Add(values);");
            sw.WriteLine("            }");
            sw.WriteLine("            return result;");
            sw.WriteLine("        }");
            sw.WriteLine("    }");
            sw.WriteLine("}");

            sw.Close();
            file.Close();
            #endregion
        }
    }
}
